package LuoGu;

import java.util.Scanner;

public class Demo5 {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int An=sc.nextInt();
        int Bn=sc.nextInt();
        int[] Arr=new int[An];
        int[] Brr=new int[Bn];
        for (int i = 0; i < An; i++) {
            Arr[i]=sc.nextInt();
        }
        for (int i = 0; i < Bn; i++) {
            Brr[i]=sc.nextInt();
        }
        int ACount=0;
        int BCount=0;
        for (int i = 0; i < n; i++) {
            int tmp=isAWin(Arr[i%An],Brr[i%Bn]);
            if(tmp==1){
              ACount++;
            }else if(tmp==-1){
                BCount++;
            }
        }
        System.out.print(ACount+" "+BCount);
    }
    public static int isAWin(int A,int B){
          if(A==B){
             return 0;
          }
          if((A==1&&B==0)||(A==0&&B==2)||(A==0&&B==3)||(A==1&&B==3)||(A==2&&B==4)||(A==3&&B==4)
          ||(A==2&&B==1)||(A==3&&B==2)||(A==4&&B==0)||(A==4&&B==1)){
              return 1;
          }else{
              return -1;
          }
    }
}
